-- inv.lua
--
-- Displays the inventory client side.
--
Inventory = {}

-- Inventory.new
-- 
-- Initilizes the inventory window.
Inventory.new = function()
  Inv = vgui.Create("DFrame")
  IsOpen = false
  local width = ScrH() / 3
  local height = width

  Inv:SetSize(height, height)
  Inv:SetMinWidth(200)
  Inv:SetMinHeight(height / 2 + 50)
  Inv:SetSizable(true)
  Inv:SetPos((ScrW() / 2) - (width / 2), (ScrH() / 2) - (height / 2)) 
  Inv:SetTitle("Inventory")
  Inv:SetVisible(false)
  Inv:SetDraggable(true)
  Inv:ShowCloseButton(true)
  Inv:SetDeleteOnClose(false)
  Inv:MakePopup()
end

-- open
-- 
-- Opens the inventory window.
Inventory.open = function()
  print("open")
  Inv:IsVisible(true)
  Inv:MakePopup()
  IsOpen = true
end

-- close
--
-- Closes the inventory window.
Inventory.close = function()
  print("close")
  Inv:SetVisible(false)
  IsOpen = false
end

function GM:KeyPress(player, key)
   if (key == IN_USE) then
      if Inventory.IsOpen then
        Inventory.close()
      else
        Inventory.open()
      end
   end
end